﻿<phone:PhoneApplicationPage 
    Name="Page"
    x:Class="Organizer.Views.TasksPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"    
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480"
    xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
    xmlns:Code="clr-namespace:BindableAppBarSample.Code;assembly=BindableAppBarSample"
    xmlns:Views="clr-namespace:Organizer.Views"
    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
    xmlns:cmd="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.WP71"
    xmlns:local="clr-namespace:Organizer.External.Helpers" shell:SystemTray.IsVisible="True">
    
    <!--реализация анимации перехода страниц-->
    <toolkit:TransitionService.NavigationInTransition>
        <toolkit:NavigationInTransition>
            <toolkit:NavigationInTransition.Backward>
                <toolkit:TurnstileTransition Mode="BackwardIn"/>
            </toolkit:NavigationInTransition.Backward>
            <toolkit:NavigationInTransition.Forward>
                <toolkit:TurnstileTransition Mode="ForwardIn"/>
            </toolkit:NavigationInTransition.Forward>
        </toolkit:NavigationInTransition>
    </toolkit:TransitionService.NavigationInTransition>
    <toolkit:TransitionService.NavigationOutTransition>
        <toolkit:NavigationOutTransition>
            <toolkit:NavigationOutTransition.Backward>
                <toolkit:TurnstileTransition Mode="BackwardOut"/>
            </toolkit:NavigationOutTransition.Backward>
            <toolkit:NavigationOutTransition.Forward>
                <toolkit:TurnstileTransition Mode="ForwardOut"/>
            </toolkit:NavigationOutTransition.Forward>
        </toolkit:NavigationOutTransition>
    </toolkit:TransitionService.NavigationOutTransition>
    
    <!--устанавливаем датаконтекст страницы-->
    <phone:PhoneApplicationPage.DataContext>
        <Views:TaskViewModel />
    </phone:PhoneApplicationPage.DataContext>
    
    <!--ресурсы страгницы. Определяем DataTemplate для списка тасков-->
    <phone:PhoneApplicationPage.Resources>
        <DataTemplate x:Key="TaskItemTemplate">
            <StackPanel x:Name="sp">
                <StackPanel Orientation="Horizontal">
                    <CheckBox HorizontalAlignment="Left" IsChecked="{Binding IsSelectedMultiSelect, Mode=TwoWay}" 
                              Visibility="{Binding ElementName=Page, Path=DataContext.Status, Converter={StaticResource manageSelectionStateToVisibilityConverter}}" />
                    <StackPanel>
                        <toolkit:ContextMenuService.ContextMenu>
                            <toolkit:ContextMenu>
                                <toolkit:MenuItem x:Name="miEdit" Header="{Binding Path=LocalizedResources.ContextMenuEdit, Source={StaticResource LocalizedStrings}}" />
                                <toolkit:MenuItem x:Name="miRemove" Header="{Binding Path=LocalizedResources.ContextMenuRemove, Source={StaticResource LocalizedStrings}}" >
                                    <i:Interaction.Triggers>
                                        <i:EventTrigger EventName="Tap">
                                            <!--<cmd:EventToCommand Command="{Binding DeleteCommand}" />-->
                                            <cmd:EventToCommand Command="{Binding ElementName=Page, Path=DataContext.RefreshCommand}" />
                                        </i:EventTrigger>
                                    </i:Interaction.Triggers>
                                </toolkit:MenuItem>
                            </toolkit:ContextMenu>
                        </toolkit:ContextMenuService.ContextMenu>
                        <TextBlock Text="{Binding Name}" Style="{StaticResource PhoneTextAccentLargeStyle}" />
                        <TextBlock Text="{Binding Description}" Style="{StaticResource TextLighter}" />
                        <i:Interaction.Triggers>
                            <i:EventTrigger EventName="Tap">
                                <cmd:EventToCommand Command="{Binding ElementName=Page, Path=DataContext.EditCommand}" CommandParameter="{Binding}" />
                            </i:EventTrigger>
                        </i:Interaction.Triggers>
                    </StackPanel>
                </StackPanel>
            </StackPanel>
        </DataTemplate>
        <!--ресурсы страгницы. Определяем DataTemplate для списка людишек-->
        <DataTemplate x:Key="ManItemTemplate">
            <StackPanel HorizontalAlignment="Stretch" Orientation="Vertical">
                <TextBlock Text="{Binding ShortName}" TextWrapping="Wrap"/>
            </StackPanel>
        </DataTemplate>
    </phone:PhoneApplicationPage.Resources>

    <!--LayoutRoot представляет корневую сетку, где размещается все содержимое страницы-->
    <Grid x:Name="LayoutRoot" Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!--TitlePanel содержит имя приложения и заголовок страницы-->
        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
            <TextBlock x:Name="ApplicationTitle" Text="{Binding Path=LocalizedResources.AppName, Source={StaticResource LocalizedStrings}}" Style="{StaticResource PhoneTextNormalStyle}"/>
            <TextBlock x:Name="PageTitle" Text="{Binding Path=LocalizedResources.TasksPage_Title, Source={StaticResource LocalizedStrings}}" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
        </StackPanel>

        <!--ContentPanel – тут размещаем наши компоненты: мультиселект лист и ScrollViewer для редактирования таска-->
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <ItemsControl x:Name="multiSelectList"  ItemTemplate="{StaticResource TaskItemTemplate}" ItemsSource="{Binding Tasks}" >
            </ItemsControl>
            <ScrollViewer Height="Auto" VerticalAlignment="Top" Width="445"
                          Visibility="{Binding Path=Status, Converter={StaticResource editStateToVisibilityConverter}}">
                <StackPanel Height="700"
                        Opacity="1" 
                        Background="{StaticResource PhoneBackgroundBrush}"                          
                        HorizontalAlignment="Left" 
                        Name="stackPanel1" 
                        VerticalAlignment="Top" Width="445">
                    <TextBlock x:Name="tbTaskName" 
                           Text="{Binding Path=LocalizedResources.TasksPage_Name, Source={StaticResource LocalizedStrings}}" 
                           Margin="12,0,0,0"
                           Style="{StaticResource TextLighter}"/>
                    <TextBox Width="445" Text="{Binding EditedTask.Name,Mode=TwoWay}" local:BindingHelper.UpdateSourceOnChange="True" HorizontalAlignment="Left" d:LayoutOverrides="Height" />

                    <TextBlock x:Name="tbTaskDescription" 
                           Text="{Binding Path=LocalizedResources.TasksPage_Description, Source={StaticResource LocalizedStrings}}" 
                           Margin="12,0,0,0"
                           Style="{StaticResource TextLighter}"/>
                    <TextBox Width="445" Height="Auto" MinHeight="200" Text="{Binding EditedTask.Description,Mode=TwoWay}" local:BindingHelper.UpdateSourceOnChange="True" HorizontalAlignment="Left" d:LayoutOverrides="Height" />
                                        
                    <CheckBox x:Name="chkBoxReminderEnable"                                                              
                           Content="{Binding Path=LocalizedResources.TasksPage_TimeRemind, Source={StaticResource LocalizedStrings}}"                           
                           IsChecked="{Binding EditedTask.RemindEnable, Mode=TwoWay}" local:BindingHelper.UpdateSourceOnChange="True"                           
                           Margin="12,0,0,0"
                           Style="{StaticResource CheckBoxLighter}"/>
                    
                    <Grid Margin="12 0 0 0"
                          HorizontalAlignment="Left"
                          d:LayoutOverrides="Height">                        
                        <Grid.RowDefinitions>
                            <RowDefinition/>
                            <RowDefinition/>
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition/>
                            <ColumnDefinition Width="216"/>
                        </Grid.ColumnDefinitions>
                        <toolkit:DatePicker x:Name="datePickRemindDate"
                           Value="{Binding EditedTask.TimeRemind, Mode=TwoWay}" local:BindingHelper.UpdateSourceOnChange="True"         
                           HorizontalAlignment="Left" 
                           d:LayoutOverrides="Height"
                           Margin="12 0 0 0"                                                                             
                           VerticalAlignment="Center"/>
                        <toolkit:TimePicker x:Name="datePickRemindTime"
                           Value="{Binding EditedTask.TimeRemindInterval, Mode=TwoWay}" local:BindingHelper.UpdateSourceOnChange="True"         
                           HorizontalAlignment="Left" 
                           d:LayoutOverrides="Height"
                           Margin="12 0 0 0"                                 
                           Grid.Column="1"                                             
                           VerticalAlignment="Center"/>                     
                    </Grid>                  
                    <TextBlock x:Name="tbLinkedMan"
                           Text="{Binding Path=LocalizedResources.TasksPage_LinkedMan, Source={StaticResource LocalizedStrings}}" 
                           Margin="12,0,0,0"
                           Style="{StaticResource TextLighter}"/>
                    <toolkit:ListPicker x:Name="listPickLinkedMan" Width="445" Height="Auto" HorizontalAlignment="Left" d:LayoutOverrides="Height"                                                                    
                                    ItemsSource="{Binding Men}"
                                    SelectionMode="Single"                                     
                                    SelectedItem="{Binding EditedTask.LinkedMan, Mode=TwoWay}"
                                    ItemTemplate="{StaticResource ManItemTemplate}">
                    </toolkit:ListPicker>                              
                    <TextBlock x:Name="tbResponsibleMan"
                           Text="{Binding Path=LocalizedResources.TasksPage_ResponsibleMan, Source={StaticResource LocalizedStrings}}" 
                           Margin="12,0,0,0"
                           Style="{StaticResource TextLighter}"/>
                    <toolkit:ListPicker x:Name="listPickResponsibleMan" Width="445" Height="Auto" MinHeight="200" HorizontalAlignment="Left" d:LayoutOverrides="Height"                                     
                                        ItemsSource="{Binding Men}" 
                                        SelectionMode="Single"                                         
                                        ItemTemplate="{StaticResource ManItemTemplate}"
                                        SelectedItem="{Binding EditedTask.ResponsibleMan, Mode=TwoWay}">
                    </toolkit:ListPicker>                               
                </StackPanel>
            </ScrollViewer>
        </Grid>
    </Grid>

    <Code:BindableApplicationBar.BindableApplicationBar>
        <Code:BindableApplicationBar>
            <!--NOTE: The ability to add more than 4 buttons and change their state based on binding. 
					If they are visible then they are added to the app bar, otherwise they are removed from the app bar.
				IMPORTANT: Always change the visibilty of the buttons in the app bar before those not in the app bar
					and avoid having 2 buttons bound to the same property for visibility-->
            <Code:BindableApplicationBar.ButtonDelegates>
                <Code:ApplicationBarIconButtonDelegate Command="{Binding AddCommand}" IconUri="/Images\Icons/appbar.add.rest.png" Text="add" 
                                                       IsVisible="{Binding Path=Status,Converter={StaticResource normalStateToVisibilityConverter}}" />
                <!--<Code:ApplicationBarIconButtonDelegate Command="{Binding ManageCommand}" IconUri="/Images\Icons/appbar.manage.rest.png" Text="manage" 
                                                       IsVisible="{Binding Path=Status,Converter={StaticResource normalStateToVisibilityConverter}}" />-->
                <Code:ApplicationBarIconButtonDelegate Command="{Binding SaveCommand}" IconUri="/Images\Icons/appbar.save.rest.png" Text="save" 
                                                       IsVisible="{Binding Path=Status,Converter={StaticResource editStateToVisibilityConverter}}" />
                <Code:ApplicationBarIconButtonDelegate Command="{Binding CancelCommand}" IconUri="/Images\Icons/appbar.cancel.rest.png" Text="cancel" 
                                                       IsVisible="{Binding Path=Status,Converter={StaticResource editStateToVisibilityConverter}}" />
                <!--<Code:ApplicationBarIconButtonDelegate Command="{Binding DeleteOrganizationsCommand}" IconUri="/Images\Icons/appbar.delete.rest.png" Text="delete"
                                                       IsVisible="{Binding Path=Status,Converter={StaticResource manageSelectionStateToVisibilityConverter}}"/>
                <Code:ApplicationBarIconButtonDelegate Command="{Binding CancelSelectionCommand}" IconUri="/Images\Icons/appbar.cancel.rest.png" Text="cancel"
                                                       IsVisible="{Binding Path=Status,Converter={StaticResource manageSelectionStateToVisibilityConverter}}"/>-->
            </Code:BindableApplicationBar.ButtonDelegates>
            <Code:BindableApplicationBar.MenuItemDelegates>
                <!--<Code:ApplicationBarMenuItemDelegate  Text="select all" Command="{Binding SelectAll}" />
                <Code:ApplicationBarMenuItemDelegate  Text="unselect all" Command="{Binding UnselectAll}" />-->
            </Code:BindableApplicationBar.MenuItemDelegates>
        </Code:BindableApplicationBar>
    </Code:BindableApplicationBar.BindableApplicationBar>

</phone:PhoneApplicationPage>
